package com.example.demo;

import com.example.demo.entity.BookCategory;
import com.example.demo.service.BookCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.servlet.ServletContext;
import java.util.List;


@Component
public class InitWebCommandLineRunner implements CommandLineRunner {

    @Autowired
    BookCategoryService bookCategoryService;

    @Autowired
    ServletContext servletContext;


    @Override
    public void run(String... args) throws Exception {

        List<BookCategory> bookCategoryList=bookCategoryService.selectAll();

        servletContext.setAttribute("bookCategories",bookCategoryList);

    }
}
